<?php
/***************************************************************************
 * 
 * Copyright (c) 2010 , Inc. All Rights Reserved
 * $Id$:YouaActionController.php,2010/05/13 11:33:35 
 * 
 **************************************************************************/
 
 
 
/**
 * @file YouaActionController.php
 * @author huqingping
 * @date 2010/05/13 11:33:35
 * @version 1.0 
 * @brief 
 *  
 **/

class YouaActionController 
{
	function checkInput($rules)
	{
		//TODO
	}
	protected $uid = 0;
	function _before()
	{
		$this->response->set('__need_login__', false);
		$this->_loadUser();
	}

	function _after()
	{
		$user = $this->user();
		$this->response->set('__user__',$user);
	}

	protected function user()
	{
		return array('uid'=>$this->uid,'uname'=>'user_'.$this->uid);
	}
	
	protected function isLogin()
	{
		return ($this->uid > 0) ;
	}

	protected function needLogin()
	{
		if (!$this->isLogin()) {
			throw new Exception('mall.u_login');
		} else {
			$this->response->set('__need_login__', true);	
		}
	}

	private function _loadUser()
	{
		$bduss = $this->request->getCookie('BDUSS');
		if ($bduss) {
			$id = 0;
			$bduid = $this->request->getCookie('BAIDUID');
			$len = strlen($bduid);
			for($i=0;$i<$len;$i++) {
				$id += ord($bduid[$i]);
			}   
			$this->uid = $id;
		}
	}
}





/* vim: set ts=4 sw=4 sts=4 tw=100 noet: */
?>
